act_site = [1 2 4 7 8];
pas_site = [3 5 6 9];

for site = 1:9
    mean_act = {};
    for time = 1:4
        cur_mean_act = {};
        for layer = 1:4
            cur_act = proj_meta(site).rd(layer,time).act;
            cur_fb_mean_act = mean(cur_act(:,1:7500),2);
            cur_pb_mean_act = mean(cur_act(:,7501:end),2);
            cur_mean_act{layer} = horzcat(cur_fb_mean_act,cur_pb_mean_act);
        end
        mean_act{time} = vertcat(cur_mean_act{:});
        cur_cc = corrcoef(mean_act{time});
        cc{site,time} = cur_cc(2);
    end
    mean_act_all{site} = horzcat(mean_act{:});
    cc_act_all{site} = corrcoef(mean_act_all{site});
%     figure;imagesc(cc_act_all{site})
end

mean_cc_act = mean(cat(3,cc_act_all{act_site}),3);
sem_cc_act = std(cat(3,cc_act_all{act_site}),0,3)/sqrt(5);
mean_cc_pas = mean(cat(3,cc_act_all{pas_site}),3);
sem_cc_pas = std(cat(3,cc_act_all{pas_site}),0,3)/sqrt(4);

figure;imagesc(mean_cc_act);colorbar
figure;imagesc(mean_cc_pas);colorbar

for ind = 2:2:8
    ccc_act(ind/2) = mean_cc_act(ind-1,ind);
    scc_act(ind/2) = sem_cc_act(ind-1,ind);
    ccc_pas(ind/2) = mean_cc_pas(ind-1,ind);
    scc_pas(ind/2) = sem_cc_pas(ind-1,ind);
end

figure;hold on
errorbar(ccc_act,scc_act)
errorbar(ccc_pas,scc_pas,'r')
ylim([0 1])